package com.book.activeMQ.productor;

import com.alibaba.fastjson.JSON;
import com.book.activeMQ.MQQueue;
import com.book.dto.TempOrderBookDto;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;

import javax.jms.Destination;
import java.util.List;
import java.util.Map;

/**
 * @Author 李锦程
 * @Date 2021/4/20 9:35 下午
 * @Package com.book.activeMQ.productor.impl
 * @Version 1.0
 */
@Service
public class ProductMQ {
    @Autowired
    private JmsTemplate jmsTemplate;

    public void updateCache(Object o) {
        Destination destination = new ActiveMQQueue(MQQueue.UPDATE_CACHE);
        jmsTemplate.convertAndSend(destination,o);
    }

    public void sendMailMessage(String orderNo) {
        Destination destination = new ActiveMQQueue(MQQueue.SEND_MAIL);
        jmsTemplate.convertAndSend(destination,orderNo);
    }

    public void saveOrderDetail(String orderNo) {
        Destination destination = new ActiveMQQueue(MQQueue.SAVE_ORDER);
        jmsTemplate.convertAndSend(destination,orderNo);
    }

    public void updateRedisNewBook(List list){
        Destination destination = new ActiveMQQueue(MQQueue.NEW_BOOK);
        String jsonObject = JSON.toJSONString(list);
        jmsTemplate.convertAndSend(destination,jsonObject);
    }

    public void updaeRedisUserCache(Integer id) {
        Destination destination = new ActiveMQQueue(MQQueue.REDIS_USER_CACHE);
        jmsTemplate.convertAndSend(destination,id);
    }

    public void saveTempOrder(Map<String, List<TempOrderBookDto>> map) {
        Destination destination = new ActiveMQQueue(MQQueue.SAVE_TEMP_ORDER);
        jmsTemplate.convertAndSend(destination,JSON.toJSONString(map));
    }

    public void resetOrderDetail(String orderCode) {
        Destination destination = new ActiveMQQueue(MQQueue.RESET_ORDER);
        jmsTemplate.convertAndSend(destination,orderCode);
    }
}
